// Package model provides an implementation of data structures and algorithms
// for representing and manipulating digital evidence.
package model

import "fmt"

// Extent represents a contiguous region of data.
type Extent struct {
	Start uint64
	End   uint64
}

// NewExtent creates and initialises a new Extent using the given start
// and end positions.
func NewExtent(start uint64, end uint64) *Extent {
	if end < start {
		return nil
	}
	return &Extent{start, end}
}

// Size returns the number of bytes contained within an extent.
func (e Extent) Size() uint64 {
	return e.End - e.Start
}

// Empty holds if the extent contains no data.
func (e Extent) Empty() bool {
	return e.Start == e.End
}

// Overlaps holds if the given extent overlaps with the receiver.
func (e Extent) Overlaps(o Extent) bool {
	return e.Start < o.End && e.End >= o.Start
}

// String returns a human-readable representation of an extent.
func (e Extent) String() string {
	return fmt.Sprintf("[%d, %d)", e.Start, e.End)
}
